using System;
using System.IO;
namespace Slaks.Web.Parser.Utils
{
	/*
	<structures>
    <structure name="TABLE" startTag="table" endTag="/table"/>
    <structure name="FORM" startTag="form" endTag="/form"/>
    <structure name="SELECT" startTag="select" endTag="/select"/>
    <structure name="FRAMESET" startTag="frameset" endTag="/frameset"/>
  </structures>
 */
	[System.Xml.Serialization.XmlRootAttribute("structure",Namespace="", IsNullable=false)]
	public class Structure
	{
		
		private string m_name;
		
		private string m_startTag;
		
		private string m_endTag;

		public Structure() {}

		public Structure(string name, string startTag, string endTag)
		{
			m_name = name;
			m_startTag = startTag;
			m_endTag = endTag;
		}

		[System.Xml.Serialization.XmlAttributeAttribute("name")]
		public string StructureName
		{
			get { return m_name; }
			set { m_name = value; }
		}

    [System.Xml.Serialization.XmlAttributeAttribute("startTag")]
		public string StructureStartTag
		{
			get { return m_startTag; }
			set { m_startTag = value; }
		}

		[System.Xml.Serialization.XmlAttributeAttribute("endTag")]
		public string StructureEndTag
		{
			get { return m_endTag; }
			set { m_endTag = value; }
		}

		public static Structure[] ReadXml(StreamReader reader)
		{
			Structures structures = null;
			if (reader!=null)
			{
				try
				{
					System.Xml.Serialization.XmlSerializer xmlser=new System.Xml.Serialization.XmlSerializer(typeof(Structures));
					structures=(Structures)xmlser.Deserialize(reader);
				}
				catch (Exception e)
				{
					throw new Exception("can't deserialize, reason: " + e.Message);
				}
      
				finally
				{
					if (reader != null) reader.Close();
				}
			}
			else 
				throw new Exception("ReadXml() : null parameter passed");
			if (structures == null || structures.structures == null) 
				throw new Exception("ReadXml : structures is null");

			return structures.structures;
		} 
	}
	[System.Xml.Serialization.XmlRootAttribute("structures",Namespace="", IsNullable=false)]
	public class Structures
	{
		[System.Xml.Serialization.XmlElementAttribute("structure",IsNullable=false)]
		public Structure [] structures;
	}

}
